<?php
/**
 * 友钱的IDFA排重接口
 * User: yaosj
 * Date: 15-12-2
 * Time: 下午4:43
 */

class IdfaInfo implements iController {


    public function output($queryArgs) {

        if (empty($queryArgs['app_id']) || empty($queryArgs['idfa'])) {
            return json_encode(array('code' =>400,'error' => '参数错误','result' => ''));
        }
        $appId = trim($queryArgs['app_id']);
        $idfas = explode(',',trim($queryArgs['idfa']));
        //保证每个提交来的idfa都有返回值
        $status = array();
        foreach($idfas as $idfa) {
            $newArr[] = '\''.$idfa.'\'';
            $status[$idfa] = '0';
        }
        $idfaStr = implode(',',$newArr);

        global $uddb;
        $results = $uddb ->getResults("SELECT * FROM youqian_idfa_data WHERE idfa in ({$idfaStr}) AND app_id = :app_id",
            array(
                ':app_id' => $appId)
        );

        foreach ($results as $result) {
            $status[$result -> idfa] = $result -> mission_status;
        }
        return json_encode(array('code' => 200,'error' => '','result' => $status));
    }
}